/*
 This file is part of Musimage, a project which makes possible listen to music
 and, at the same time, watch pictures related with that music.
 Copyright (C) 2006  David Garcia Narbona 

 Musimage is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Musimage is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Musimage; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package brokerExt;

import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.core.Agent;

// Clase que modela el Agente broker externo
public class Server extends Agent {

	// ** Atributos **///////////////////////////////////////
	private ServerBehaviour serverCyclicBehaviour;

	// /////////////////////////////////////////////////////

	// ** Metodos **////////////////////////////////////////

	// Metodo que se ejecuta una vez creado el Agente
	protected void setup() {

		serverCyclicBehaviour = new ServerBehaviour();

		System.out.println("Starting external broker...");

		// Registrar el servicio en el Facilitador de Directorio, (DF)
		DFAgentDescription DF = new DFAgentDescription();
		DF.setName(getAID());

		ServiceDescription serviceDescription = new ServiceDescription();
		serviceDescription.setType("External broker");
		serviceDescription.setName("EBroker-Musimage");

		DF.addServices(serviceDescription);

		try {

			DFService.register(this, DF);
		} catch (FIPAException fipaEx) {
			fipaEx.printStackTrace();
		}
		// ///////////////////////////////////////////////////////////

		addBehaviour(serverCyclicBehaviour);

	}

	// Metodo que se ejecuta antes de terminar la ejecucion de un agente
	protected void takeDown() {
		System.out.println("Taking down server...");
	}

	// ////////////////////////////////////////////////////

}
